package com.aric.springbootmusic.controller;

import com.aric.springbootmusic.service.PermissionService;
import com.aric.springbootmusic.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private PermissionService permissionService;

    /**
     * 查询所有权限
     */
    @PreAuthorize("hasAuthority('RoleAuthorityList')")
    @GetMapping("/selectAllPermission")
    public Result selectAllPermission(){
        return permissionService.findAllPermission();
    }

    @PreAuthorize("hasAuthority('RoleAuthorityList')")
    @GetMapping("/selectRoleAuthor")
    public Result selectRoleAuthor(@RequestParam Integer id){
        return permissionService.findRoleAuthor(id);
    }

    @PreAuthorize("hasAuthority('RoleAuthorityList')")
    @GetMapping("/selectAllRight")
    public Result selectAllRight(){
        return permissionService.findAllRight();
    }
}
